﻿using System;
using System.ComponentModel;
using System.Reflection;

namespace SedionFormDesigner.CusControls.Infrastructure
{
    public static class ControlHelper
    {
        public static void SetPropertyVisibility(Object obj, String propertyName, Boolean visible)
        {
            Type type = typeof(BrowsableAttribute);
            PropertyDescriptorCollection props = TypeDescriptor.GetProperties(obj);
            AttributeCollection attrs = props[propertyName].Attributes;
            FieldInfo fld = type.GetField("browsable", BindingFlags.Instance | BindingFlags.NonPublic);
            fld.SetValue(attrs[type], visible);
        }
    }
}
